﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace LOGIN
{
    public partial class Change_stu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["name"] == null)
            {
                Response.Redirect("index.aspx");
            }
            else this.login.Text = "" + Session["name"].ToString() + "同学，你已经成功进入登录页面";

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112122;uid=2014112122;pwd=19950123";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string strSql = "UPDATE  Login  SET         Password = " + this.chaPwd.Text + ", Sex = N'" + this.chaSex.Text + "', Number = N'" + this.chaNo.Text + "', College = N'" + this.chaCol.Text + "'  WHERE   (Name = N'" + this.chaName.Text + "')";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                int iUpd = cmd.ExecuteNonQuery();
                if (iUpd < 1)
                {
                    this.lblInfo.Text = "修改失败！";
                }
                else
                {
                    this.lblInfo.Text = "已完成修改！";
                }
                //Response.Write("<script>alert('恭喜，修改资料成功。单击“确定”返回登录页面。');location.href='index.aspx';</script>");
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string name;
            name = Session["name"].ToString();
            this.qq.Text = name;
            string strCn = "server=pc.hstc.cn;database=dhd2014112122;uid=2014112122;pwd=19950123";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string strNo = this.qq.Text;
                string strSql = "SELECT   Name, Password, Number, Sex, College  FROM      Login  WHERE   (Name = N'" + this.qq.Text + "')";

                SqlCommand cmd = new SqlCommand(strSql, cn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    this.chaName.Text = dr["Name"].ToString();
                    this.chaPwd.Text = dr["Password"].ToString();
                    this.chaNo.Text = dr["Number"].ToString();
                    this.chaSex.Text = dr["Sex"].ToString();
                    this.chaCol.Text = dr["College"].ToString();
                }
                dr.Close();
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }
        protected void exit_Click(object sender, EventArgs e)
        {

            Response.Redirect("index.aspx");
        }

        protected void update_Click(object sender, EventArgs e)
        {
            Response.Redirect("Change_stu.aspx");
        }

        protected void text_Click(object sender, EventArgs e)
        {

        }

        protected void mark_Click(object sender, EventArgs e)
        {
            Response.Redirect("mark.aspx");
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("Main_Stu.aspx");
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["Theme"] = this.DropDownList1.SelectedValue.ToString();
        }

        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] != null)
                this.Theme = Session["Theme"].ToString();
        }


    }
}